const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');

module.exports = {
    mode: 'none',
    entry: {
        index: './src/index.js',
        album: './src/album.js'
    },
    output: {
        filename: '[name]-[hash].bundle.js',
        path: path.join(__dirname, 'dist'),
    },
    module: {
        rules: [
            {
                test: /.js$/,
                use: {
                    loader: 'babel-loader'
                },
            },
            {
                test: /.css$/,
                use: [
                    'style-loader',
                    'css-loader'
                ]
            },
            {
                test: /.html$/,
                use: {
                  loader: 'html-loader'
                }
            },
            {
                test: /.png$/,
                use: {
                    loader: 'url-loader',
                    options: {
                        limit: 10* 1024 //10KB
                    }
                }
            }
        ]
    },
    plugins: [
        new CleanWebpackPlugin(),
        new HtmlWebpackPlugin({
            title: 'webpack plugin sample',
            meta: {
                viewport: 'width=device-width',
            },
            template: './src/index.html',
            filename: 'index.html',
            chunks: ['index']
        }),
        // 用于生成 about.html
        new HtmlWebpackPlugin({
            title: 'webpack plugin multi entry',
            template: './src/album.html',
            filename: 'album.html',
            chunks: ['album']
        })
    ]
}
